/*
 *
 * Copyright (C) 2012 Walter Lütgenau
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package offset.nodes.client.dialog.newnode.model;

import java.net.URL;
import offset.nodes.client.chooser.model.NewFolder;
import offset.nodes.client.model.ServerModel;
import offset.nodes.client.dialog.newnode.view.FolderPanel;

/**
 *
 * @author Walter Lütgenau
 */
public class FolderNewNodeConfigurator extends AbstractNewNodeConfigurator implements NewNodeConfigurator {

    @Override
    public ObjectType getObjectType() {
            ContentType[] folderContentTypes = new ContentType[]{
                new ContentType("", "none", "application/octet-stream", getBundle()),
                new ContentType("binary", "binary", "application/octet-stream", getBundle()),
                new ContentType("css", "css", "text/css", getBundle()),
                new ContentType("html", "html", "text/html", getBundle())
            };

            return new ObjectType(bundle, "folder.name", "folder.description", new Step[]{new Step(bundle, "folder.step1.name", new FolderPanel(folderContentTypes))}, 
                    new ServiceProcessor(getService(), getPath()) {

                public URL process() {
                    NewFolder.Request request = new NewFolder.Request();
                    FolderPanel panel = (FolderPanel) getObjectType().getSteps()[1].getPanel();

                    request.setPath(getPath());
                    request.setName(panel.getFolderName());
                    request.setDefaultContentType((String) panel.getDefaultContentType());

                    try {
                        ServerModel model = new ServerModel(getService());
                        model.sendRequest(request);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    return null;
                }
            });

    }

}
